<?php
/**
 * Created by PhpStorm.
 * User: david
 * Date: 3/22/19
 * Time: 8:30 PM
 */

namespace App\Transformers;


use App\Models\Job;
use League\Fractal\TransformerAbstract;

class JobTransformer extends TransformerAbstract
{
    protected $defaultIncludes = ['project'];

    public function transform(Job $job)
    {
        return [
            'id' => $job->id,
            'name' => $job->name,
            'project_id' => $job->project_id,
            'school' => $job->school,
            'post' => $job->post,
            'school_name' => Job::SCHOOL_NAME[(int) $job->school],
            'education' => $job->education,
            'education_name' => Job::EDUCATION_NAME[(int) $job->education] ?? '',
            'sex' => $job->sex,
            'sex_name' => Job::SEX_NAME[(int) $job->sex],
            'specialty1' => $job->specialty1,
            'specialty2' => $job->specialty2,
            'specialty3' => $job->specialty3,
            'number' => $job->number,
            'created_at' => $job->created_at ? $job->created_at->toDateTimeString() : null,
            'updated_at' => $job->updated_at ? $job->updated_at->toDateTimeString() : null,
        ];
    }

    public function includeProject(Job $job)
    {
        if (is_null($job->project)) {
            return null;
        }
        return $this->item($job->project, new ProjectTransformer());
    }
}